package 一半异步_一半同步;



class Task{
	public void doLongTimeTask() {
		for(int i = 0; i < 100 ; i++) {
			System.out.println("nosynchronized threadName="+ Thread.currentThread().getName() + " i=" + (i + 1));
		}
		System.out.println("");
		synchronized(this) {
			for(int i = 0; i < 100 ; i++) {
				System.out.println("synchronized threadName="+ Thread.currentThread().getName() + " i=" + (i + 1));
			}
	}
}
}
class MyThread1 extends Thread{
	private Task task;
	public MyThread1(Task task) {
		super();
		this.task=task;
	}
	public void run() {
		super.run();
		task.doLongTimeTask();
	}
	
}
class MyThread2 extends Thread{
	private Task task;
	public MyThread2(Task task) {
		super();
		this.task=task;
	}
	public void run() {
		super.run();
		task.doLongTimeTask();
	}
	
}
public class Run {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Task task=new Task();
		MyThread1 thread1=new MyThread1(task);
		thread1.start();
		MyThread2 thread2=new MyThread2(task);
		thread2.start();
	}

}
